let baseUrl = 'http://rap2api.taobao.org/app/mock/239427/get'
function GET(url){
	var url = baseUrl+url;
	return new Promise((resolve,reject)=>{
		uni.request({
			url,
			method:'get',
			success: (res) => {
				if(res.data.code==1){
					resolve(res.data.data)
				}
			},
			fail:(err)=>{
				reject(err)
				uni.showToast({
					title:'网络错误,请重试'
				})
			}
		})
	})
}

function loadMore(that,url,p,target){
	//that  调用这个方法函数的组件对象
	//target  将新的数据包设置给data中的哪个字段
	var url = baseUrl+url;
	return new Promise((resolve,reject)=>{
		p++;
		console.log(p)
		uni.showLoading()
		uni.request({
			url,
			method:'get',
			data:{
				page:p,
				limit:10
			},
			success: (res) => {
				console.log(res)
				let newList = res.data.data;
				if(newList.length>0){
					that[target] = [...that[target],...newList];
				}else{
					p--;
				}
				resolve(p)
				uni.hideLoading()
			}
		})
	})
}


export {
	GET,
	loadMore
}